﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ITAP.ContourBuilder.Components;

namespace ITAP.ContourBuilder.Manipulation
{
    public class CommandRemoveComponents : SerializedCommand
    {
        public CommandRemoveComponents(ContourControl control)
            : base(control)
        {
        }

        public override void ObtainPeripheryState(GlobalPeripheryState state)
        {
            base.ObtainPeripheryState(state);
            if (state.KeyboardState.KeyMode == KeyMode.Down && state.KeyboardState.KeyState.KeyCode == Keys.Delete)
            {
                foreach (IContourComponent selectedComponent in this.control.ContourContainer.SelectedComponentsStack)
                    selectedComponent.Parent.RemoveInnerComponent(selectedComponent);

                this.control.ContourContainer.SelectedComponentsStack.Clear();
                this.control.ToleranceManager.Visit(this.control.ContourContainer);
                this.control.UpdateModel();
            }
        }

        public override string ToString()
        {
            return "Удаление";
        }
    }
}
